<?php
/**
 * Show the feed metadata change log
 *
 * @author University of London Computer Centre
 * @version 1.4.0 - Release Candidate 2
 * @package ArchivePress
 * @subpackage pages
 * @global ArchivePress $ArchivePress
 * @global ArchivePressLog $ArchivePressLog
 */

// globals
global $ArchivePress;
global $ArchivePressLog;

// FEED ID
$feed_id = 0;
if(isset($_GET["feed_id"])){
    $feed_id = (int)attribute_escape($_GET["feed_id"]);
}

// GET FEED
$feed = $ArchivePress->getFeed($feed_id);

echo '<div class="wrap">
        <div class="icon32" id="icon-archivepress"><br /></div>
        <h2>'.__("Feed Metadata  Changelog", ARCHIVEPRESS).'
            <a class="button add-new-h2" href="admin.php?page=archivepress/pages/edit-posts.php" title="'.__("Back to feeds", ARCHIVEPRESS).'" >'.__("Back to feeds", ARCHIVEPRESS).'</a>
            <span class="subtitle">'.sprintf(__("Metadata for Feed &ldquo;%s&rdquo;", ARCHIVEPRESS), $ArchivePress->cleanOutput($feed["name"])).'</span>
        </h2>';



// PAGINATION
$paging = "";
if(isset($_GET['paging'])){
    $paging = attribute_escape($_GET['paging']);
}
// get logs
$logs = $ArchivePress->getMetadataChangeLog($feed_id);

$items = count($logs);

$p = new pagination;
$p->items($items);
$p->limit(15); // Limit entries per page
$p->target(str_replace("&","&amp;",$_SERVER['REQUEST_URI']));
$p->currentPage($paging); // Gets and validates the current page
$p->calculate(); // Calculates what to show
$p->parameterName('paging');
$p->adjacents(2); //No. of page away from the current page

if($paging == "") {
    $p->page = 1;
} else {
    $p->page = $paging;
}

$p->prevT = "";
$p->nextT = "";
$p->displaying = __("Displaying", ARCHIVEPRESS);
$p->of = __("of", ARCHIVEPRESS);

// limit for query
$limit = " LIMIT " . ($p->page - 1) * $p->limit  . ", " . $p->limit;

echo'

        <div class="tablenav">


            <div class="tablenav">
                <div class="tablenav-pages">
                    '.$p->getOutput().'
                </div>
            </div>

            <div class="clear"></div>
        </div>

        <div class="clear"></div>

        <table cellspacing="0" class="widefat post fixed">
            <thead>
                <tr>
                    <th style="" class="manage-column column-arpr_changelogversion" scope="col">'.__("Version", ARCHIVEPRESS).'</th>
                    <th style="" class="manage-column column-arpr_metalogdate" scope="col">'.__("Date", ARCHIVEPRESS).'</th>
                    <th style="" class="manage-column column-arpr_changelog" scope="col">'.__("Changes", ARCHIVEPRESS).'</th>
                </tr>
            </thead>

            <tfoot>
                <tr>
                    <th style="" class="manage-column column-arpr_changelogversion" scope="col">'.__("Version", ARCHIVEPRESS).'</th>
                    <th style="" class="manage-column column-arpr_metalogdate" scope="col">'.__("Date", ARCHIVEPRESS).'</th>
                    <th style="" class="manage-column column-arpr_changelog" scope="col">'.__("Changes", ARCHIVEPRESS).'</th>
                </tr>
            </tfoot>

            <tbody>';

// print feeds
if(count($logs) > 0){
    $i = 0;
    foreach($logs as $log){
        if((count($logs) - $i) != 1) {
            $changes = $log["changes"];
        } else {
            $changes = __("This is the First Version", ARCHIVEPRESS);
        }
            echo'
                    <tr valign="top" class="alternate iedit" id="log'.$log["id"].'">
                        <td class="column-arpr_changelogversion"><a title="'.__("See this Version", ARCHIVEPRESS).'" href="admin.php?page=archivepress/pages/metadata.php&amp;meta_id='.$log["id"].'">Version '.(count($logs) - $i).'</a></td>
                        <td class="column-arpr_metalogdate">'.date('F jS, Y @ H:i',$ArchivePress->cleanOutput(strtotime($log["date_time"]))).'</td>
                        <td class="column-arpr_changelog">'.$changes.'</td>
                    </tr>';
            $i++;
    }
} else {
    echo '<tr valign="top" class="alternate iedit" id="feed-0"><td colspan="3">'.__("No Logs found", ARCHIVEPRESS).'</td></tr>';
}

echo'
            </tbody>
        </table>
        <div class="tablenav">

            <div class="tablenav">
                <div class="tablenav-pages">
                    '.$p->getOutput().'
                </div>
            </div>
            <br class="clear" />
        </div>
    </div>';

?>